public class ExceptionTest {
    private String username = "admin";
    private String password = "123456";
    public void login(String username,String password) throws UserNameException,PasswordException{
        if(!this.username.equals(username)){
            throw new UserNameException("用户名错误");
        }
        if(!this.password.equals(password)){
            throw new PasswordException("密码错误");
        }
        System.out.println("登陆成功");
    }

    public static void main(String[] args) {
        ExceptionTest exceptionTest = new ExceptionTest();
        try{
            exceptionTest.login("admi","123456");
        }catch (UserNameException e){
            e.printStackTrace();
        }catch (PasswordException e){
            e.printStackTrace();
        }
    }
}
